import request from '@/utils/request'
import type { IMyUserResData, PatientList, Patient } from '@/types/user'
import type {
  ILoginData,
  // IResponseData,
  ICodeType,
  ILoginCodeData
} from '@/types/user'
// 通过枚举统一维护接口地址
// enum USER_URL {
//   loginByPassword = '/login/password',
//   getCode = '/code',
//   loginByCode = '/login'
// }

// 定义一个泛型函数，接受一个类型参数T，表示返回的数据中的data的类型
// post请求接受第二个类型参数才是响应的数据类型
export const loginByPassword = <T>(obj: ILoginData) =>
  // axios.post<any, IResponseData<T>>(USER_URL.loginByPassword, obj)
  request<T>('/login/password', 'post', obj)

export const getCode = (obj: ICodeType) =>
  // axios.get<any, IResponseData<{ code: string }>>(USER_URL.getCode, {
  //   params: obj
  // })
  request('/code', 'get', obj)

// 验证码登录
export const loginByCode = <T>(obj: ILoginCodeData) =>
  // axios.post<any, IResponseData<T>>(USER_URL.loginByCode, obj)
  request<T>('/login', 'post', obj)

// 获取个人用户信息
export const getMyUser = () => request<IMyUserResData>('/patient/myUser')

// 查询患者列表信息
export const getPatientList = () => request<PatientList>('/patient/mylist')

// 添加患者信息
export const addPatient = (patient: Patient) =>
  request('/patient/add', 'post', patient)

// 编辑患者信息
export const updatePatient = (patient: Patient) =>
  request('/patient/update', 'PUT', patient)

// 删除患者信息
export const deletePatient = (id: string) =>
  request(`/patient/del/${id}`, 'delete')
